
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    //JEuler.system.loadJS("data/???.dat");
    JEuler.system.printCaption("4");
    JEuler.system.startTimerCount();
    
    function isPalindromic(num) {
        var a=[], tmp=num, n, p;
        do {
            p = tmp%10;
            a.push(p);
            tmp = (tmp-p)/10;
        } while (tmp>0);
        for(var i=0; i<Math.floor(a.length/2); i++) {
            if(a[i]!=a[a.length-1-i]) return false;
        }
        return true;
    }
    
    var maxNum = 0, tmp;    
    for(var i=100; i<=999; i++) {
        for(var j=999; j>=100; j--) {
            tmp = i*j;
            if(isPalindromic(tmp) && tmp>maxNum) {
                JEuler.system.print("Find palindromic number : " + tmp);
                maxNum = tmp;
                break;
            }
        }
    }
    
    JEuler.system.print("largest palindromic number is : " + maxNum);
    JEuler.system.printTimerCount();
    
})();
